package com.fqdf.framework.android.util;

import android.content.Context;
import android.support.annotation.ColorInt;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
import com.fqdf.framework.android.R;

public class DialogUtil {
    /**
     * 弹出Toast消息
     *
     * @param msg
     */
    public static void ToastMessage(Context con, String msg) {
        Toast.makeText(con, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * 弹出Toast消息
     *
     * @param con 上下文内容
     * @param msg 消息资源id
     */
    public static void ToastMessage(Context con, int msg) {
        Toast.makeText(con, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * 创建显示进度处理的dialog
     *
     * @param context
     * @param title
     * @param content
     * @return
     */
    public static MaterialDialog createProgressDialog(Context context, String title, String content) {
        return createProgressDialog(context, title, content, false);
    }

    public static MaterialDialog createDefaultProgressDialog(Context context, String content) {
        return createProgressDialog(context, null, content, true);
    }

    public static MaterialDialog createDefaultProgressDialogNoCancel(Context context, String content) {
        return createProgressDialog(context, null, content, false);
    }

    /**
     * 创建禁止取消的提交等待框
     *
     * @param context
     * @return
     */
    public static MaterialDialog createNoCancelSubmit(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.is_submit), false);
    }

    /**
     * 创建加载等待框
     *
     * @param context
     * @return
     */
    public static MaterialDialog createLoadingDialog(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.is_loading), true);
    }

    /**
     * 创建加载等待框--不可取消
     *
     * @param context
     * @return
     */
    public static MaterialDialog createNoCancelLoadingDialog(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.is_loading), false);
    }

    /**
     * 创建上传图片--不可取消
     *
     * @param context
     * @return
     */
    public static MaterialDialog createNoCancelUploadImgDialog(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.upload_iamge), false);
    }

    /**
     * @param context
     * @param title
     * @param content
     * @param cancel
     * @return
     */
    public static MaterialDialog createProgressDialog(Context context, String title, String content, boolean cancel) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .progress(true, 0)
                .widgetColorRes(R.color.a)
                .canceledOnTouchOutside(cancel)
                .cancelable(cancel).build();
    }

    public static void showIndeterminateProgress(MaterialDialog dialog) {
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    public static void hideIndeterminateProgress(MaterialDialog dialog) {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    public static MaterialDialog creatBaseKnowDialog(Context context, String content) {

        return creatBaseDialog(context, null, content, context.getString(R.string.know), null);
    }

    public static MaterialDialog creatBaseDialog(Context context, String content) {
        return creatBaseDialog(context, null, content);
    }

    public static MaterialDialog creatBaseDialog(Context context, String title, String content) {
        return creatBaseDialog(context, title, content, context.getString(R.string.confirm), null);
    }

    public static MaterialDialog creatBaseNoTitleDialog(Context context, String content, String positiveText, String negativeText) {
        return creatBaseDialog(context, null, content, positiveText, negativeText);
    }

    public static MaterialDialog creatBaseDialog(Context context, String title, String content, String positiveText, String negativeText) {

        return creatBaseDialog(context, title, content, positiveText, AndroidUtils.getColor(context, R.color.f)
                , negativeText, AndroidUtils.getColor(context, R.color.f));
    }

    /**
     * 创建基本的basedialog
     *
     * @param context       上下文内容
     * @param title         标题
     * @param content       内容
     * @param positiveText  确认按钮的内容
     * @param positiveColor 确认按钮的颜色
     * @param negativeText  取消按钮的内容
     * @param negativeColor 取消按钮的颜色
     * @return dialog对象
     */
    public static MaterialDialog creatBaseDialog(Context context, String title, String content, String positiveText
            , @ColorInt int positiveColor, String negativeText, @ColorInt int negativeColor) {

        MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
        if (!CheckLogicUtil.isEmpty(title)) {
            builder.title(title);
        }
        if (!CheckLogicUtil.isEmpty(content)) {
            builder.title(content);
        }

        if (!CheckLogicUtil.isEmpty(positiveText)) {
            builder.positiveText(positiveText);
            builder.positiveColor(positiveColor);
        }

        if (!CheckLogicUtil.isEmpty(negativeText)) {
            builder.negativeText(negativeText);
            builder.negativeColor(negativeColor);
        }

        return builder.build();
    }



}
